home *** CD-ROM | disk | FTP | other *** search
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- #include "shared.fx"
- #include "lighting.fx"
-
- //------------------------------------------------------------------------------------------------------
- //- Static parameters
- //------------------------------------------------------------------------------------------------------
-
- texture DiffuseMap;
- float4 FadeFactor; //shared between all occurences of this shader.
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- struct FadeVertexShaderInput
- {
- float4 Position : POSITION;
- float2 DiffuseUv : TEXCOORD0;
- };
-
- //------------------------------------------------------------------------------------------------------
-
- struct FadeVertexShaderOutput
- {
- float4 Position : POSITION;
- float4 FadeFactor: COLOR0;
- float2 DiffuseUv : TEXCOORD0;
- };
-
- //------------------------------------------------------------------------------------------------------
-
- struct FadeSunlightVertexShaderOutput
- {
- float4 Position : POSITION;
- float4 FadeFactor : COLOR0;
- float2 DiffuseUv : TEXCOORD0;
- float3 LightingComponent : TEXCOORD1;
- };
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- FadeVertexShaderOutput FadeVertexShaderTech1Pass1 (const FadeVertexShaderInput input);
- FadeSunlightVertexShaderOutput FadeSunlightVertexShaderTech1Pass1(const FadeVertexShaderInput input);
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- FadeVertexShaderOutput FadeVertexShaderTech1Pass1(const FadeVertexShaderInput input)
- {
- FadeVertexShaderOutput output;
-
- // output position into world+view+projection space
- output.Position = mul (input.Position,WorldCameraProjection);
-
- // Diffuse Uv output
- output.DiffuseUv = input.DiffuseUv;
-
- // use color0 to store the fade factor!!
- output.FadeFactor = FadeFactor;
-
- return output;
- }
-
- //------------------------------------------------------------------------------------------------------
-
- #define SUN_IMPACT_RADIUS 700.0f
- #define SUN_FALLOFF_ZONE 1600.0f
- #define SUN_FALLOFF_SLOPE 1.0f / (SUN_IMPACT_RADIUS - SUN_FALLOFF_ZONE)
- #define SUN_ORIGIN_IMPACT_INTENSITY 1.0f - (SUN_IMPACT_RADIUS * SUN_FALLOFF_SLOPE)
-
-
- FadeSunlightVertexShaderOutput FadeSunlightVertexShaderTech1Pass1(const FadeVertexShaderInput input)
- {
- FadeSunlightVertexShaderOutput output;
-
- // output position into world+view+projection space
- output.Position = mul (input.Position,WorldCameraProjection);
-
- // Diffuse Uv output
- output.DiffuseUv = input.DiffuseUv;
-
- // use color0 to store the fade factor!!
- output.FadeFactor = FadeFactor;
-
- // compute sunlight omni impact
- float omniDistanceFromVertex = distance(ObjectLocalLightPosition[0].xyz ,input.Position.xyz);
- output.LightingComponent.xyz = saturate( omniDistanceFromVertex * SUN_FALLOFF_SLOPE + SUN_ORIGIN_IMPACT_INTENSITY);
-
- return output;
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- technique NoFade
- <
- int Priority = 1;
- int TechniqueIndex = 0;
- int DeviceType = HWSHADER_ONLY;
- int LightingType = INTEGRATED_LIGHTING;
- string RenderingType = "Standard";
- >
- {
- pass pass1
- {
- Texture[0] = <DiffuseMap>;
- MinFilter[0] = LINEAR;
- MagFilter[0] = LINEAR;
- MipFilter[0] = LINEAR;
- AddressU[0] = WRAP;
- AddressV[0] = WRAP;
- CullMode = CW;
- ZEnable = true;
- ZFunc = LESSEQUAL;
- ZWriteEnable = true;
- AlphaBlendEnable = false;
- AlphaTestEnable = true;
- AlphaRef = 192;
- AlphaFunc = GREATEREQUAL;
-
- VertexShader = compile vs_1_1 FadeVertexShaderTech1Pass1();
-
- PixelShader =
- asm
- {
- ps_1_1
-
- tex t0 // Diffuse map
-
- mov r0,t0 // ok take the texture alpha component as alpha, no pb.
- };
- }
- }
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- technique NoFadeWithAmbient
- <
- int Priority = 1;
- int TechniqueIndex = 1;
- int DeviceType = HWSHADER_ONLY;
- int LightingType = INTEGRATED_LIGHTING;
- string RenderingType = "Standard";
- >
- {
- pass pass1
- {
- Texture[0] = <DiffuseMap>;
- MinFilter[0] = LINEAR;
- MagFilter[0] = LINEAR;
- MipFilter[0] = LINEAR;
- AddressU[0] = WRAP;
- AddressV[0] = WRAP;
- CullMode = CW;
- ZEnable = true;
- ZFunc = LESSEQUAL;
- ZWriteEnable = true;
- AlphaBlendEnable = false;
- AlphaTestEnable = false;
- // AlphaRef = 192;
- // AlphaFunc = GREATEREQUAL;
-
- VertexShader = compile vs_1_1 FadeSunlightVertexShaderTech1Pass1();
-
- PixelShaderConstant[0] = <AmbientColor>;
- PixelShaderConstant[1] = <DiffuseColor[0]>;
- PixelShaderConstant[2] = <DiffuseColor[1]>;
-
- PixelShader =
- asm
- {
- ps_1_1
-
- tex t0 // Diffuse map
- texcoord t1 // diffuse lighting component sunlight
-
- // mad r0,c1,t1,t0 // add diffuse component sun light to diffuse tex
- // mad r0.rgb,c2,1-t1,r0 // add diffuse component back light
- // mul r0.rgb,r0,c0 + mov r0.a, c0.a // ambient global modulate
-
-
- // mul_sat r0,t0,c0 // ambient modulate
- mad_sat r0,c2,1-t1,t0 // add diffuse component back light
- mul_sat r0.rgb, r0, c0 // ambient modulate only back light and texture
- mad_sat r0.rgb,c1,t1,r0 + mov r0.a, c0.a // add diffuse component sun light and fill alpha
- };
- }
- }
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- technique Fade
- <
- int Priority = 0;
- int NeedSorting = 1;
- int TechniqueIndex = 2;
- int DeviceType = HWSHADER_ONLY;
- int LightingType = INTEGRATED_LIGHTING;
- string RenderingType = "Standard";
- >
- {
- pass pass1
- {
- Texture[0] = <DiffuseMap>;
- MinFilter[0] = LINEAR;
- MagFilter[0] = LINEAR;
- MipFilter[0] = LINEAR;
- AddressU[0] = WRAP;
- AddressV[0] = WRAP;
- CullMode = CW;
- ZEnable = true;
- ZFunc = LESSEQUAL;
- ZWriteEnable = false;
-
- AlphaTestEnable = false; // eliminate too thin pixels
- // AlphaRef = 100;
- // AlphaFunc = GREATER;
- AlphaBlendEnable = true; //use alpha blend !!! I beg thee.
- SrcBlend = SRCALPHA;
- DestBlend = INVSRCALPHA;
-
- VertexShader = compile vs_1_1 FadeVertexShaderTech1Pass1();
-
- PixelShader =
- asm
- {
- ps_1_1
-
- tex t0 // Diffuse map
-
- mov r0.rgb,t0 + mul r0.a, t0.a, v0.a // ponderate the texture alpha by a global alpha blend -> fade.
- };
- }
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- technique FadeWithAmbient
- <
- int Priority = 0;
- int NeedSorting = 1;
- int TechniqueIndex = 3;
- int DeviceType = HWSHADER_ONLY;
- int LightingType = INTEGRATED_LIGHTING;
- string RenderingType = "Standard";
- >
- {
- pass pass1
- {
- Texture[0] = <DiffuseMap>;
- MinFilter[0] = LINEAR;
- MagFilter[0] = LINEAR;
- MipFilter[0] = LINEAR;
- AddressU[0] = WRAP;
- AddressV[0] = WRAP;
- CullMode = CW;
- ZEnable = true;
- ZFunc = LESSEQUAL;
- ZWriteEnable = false;
-
- AlphaTestEnable = false; // eliminate too thin pixels
- // AlphaRef = 100;
- // AlphaFunc = GREATER;
- AlphaBlendEnable = true; //use alpha blend !!! I beg thee.
- SrcBlend = SRCALPHA;
- DestBlend = INVSRCALPHA;
-
- VertexShader = compile vs_1_1 FadeSunlightVertexShaderTech1Pass1();
-
- PixelShaderConstant[0] = <AmbientColor>;
- PixelShaderConstant[1] = <DiffuseColor[0]>;
-
- PixelShader =
- asm
- {
- ps_1_1
-
- tex t0 // Diffuse map
- texcoord t1 // diffuse lighting component
-
- //mul r0,t0,t0
- mul r1,t0,c0 // ambient modulate
- mul r0,t0,t1 // modulate diffuse by sun aura
- mad r0.rgb,c1,r0,r1 + mul r0.a, t0.a, v0.a // add diffuse component and ponderate alpha by global alpha
- };
- }
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- technique techTnL_0
- <
- int Priority = 1;
- int TechniqueIndex = 0;
- int DeviceType = TNL_ONLY;
- int LightingType = INTEGRATED_LIGHTING;
- string RenderingType = "Standard";
- >
- {
- pass pass1
- {
- WorldTransform[0] = <WorldCameraProjection>;
-
- Texture[0] = <DiffuseMap>;
-
- ColorArg1[0] = TEXTURE;
- ColorOp[0] = SELECTARG1;
- AlphaArg1[0] = TEXTURE;
- AlphaOp[0] = SELECTARG1;
-
- ColorOp[1] = DISABLE;
- AlphaOp[1] = DISABLE;
-
- MinFilter[0] = LINEAR;
- MagFilter[0] = LINEAR;
- MipFilter[0] = LINEAR;
-
- AddressU[0] = WRAP;
- AddressV[0] = WRAP;
-
- CullMode = CW;
- ZEnable = true;
- ZFunc = LESSEQUAL;
- ZWriteEnable = true;
- AlphaBlendEnable = false;
- AlphaTestEnable = true;
- AlphaRef = 192;
- AlphaFunc = GREATEREQUAL;
-
- VertexShader = NULL;
- PixelShader = NULL;
- }
- }
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- #include "mesh_shadow.fx"
- #include "mesh_shadow_projector.fx"
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
-